const Router = require("koa-router")
const Server = require('./server')
const Check = require('./check')
const { auth } = require('@/lib/auth')

/**
 * 路由对象
 * @type {Router}
 */
const router = new Router({
	prefix: '/home-link'
})

/**
 * 获取所有首页链接数据
 */
router.get("/all", async (ctx, next) => {
	const data = await Server.all(ctx)
	ctx.sendSuccess(data)
})

/**
 * 添加
 */
router.post("/add", auth, async (ctx, next) => {
	Check.add(ctx)
	const data = await Server.add(ctx)
	ctx.sendSuccess(data)
})

/**
 * 修改
 */
router.post("/update", auth, async (ctx, next) => {
	Check.update(ctx)
	const data = await Server.update(ctx)
	ctx.sendSuccess(data)
})

/**
 * 删除
 */
router.delete("/remove", auth, async (ctx, next) => {
	Check.remove(ctx)
	const data = await Server.remove(ctx)
	ctx.sendSuccess(data)
})

/**
 * 详情
 */
router.get("/detail", auth, async (ctx, next) => {
	Check.detail(ctx)
	const data = await Server.detail(ctx)
	ctx.sendSuccess(data)
})

/**
 * 添加到回收站
 */
router.get("/dustbin-push", auth, async (ctx, next) => {
	Check.dustbin_push(ctx)
	const data = await Server.dustbin_push(ctx)
	ctx.sendSuccess(data)
})

/**
 * 从回收站去除
 */
router.get("/dustbin-pop", auth, async (ctx, next) => {
	Check.dustbin_pop(ctx)
	const data = await Server.dustbin_pop(ctx)
	ctx.sendSuccess(data)
})

/**
 * 获取回收站数据
 */
router.get("/dustbin-all", auth, async (ctx, next) => {
	Check.dustbin_all(ctx)
	const data = await Server.dustbin_all(ctx)
	ctx.sendSuccess(data)
})


module.exports = router
